<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>导入客户信息</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <div align="center">
            <form id="agentForm">
                <div class="field">
                    <jsp:include page="../../system/sysUlFilesRec/sysSysUlFilesRecUpload.jsp" flush="true">
                        <jsp:param name="fileNum" value="1"/>
                        <jsp:param name="filePath" value="mcrBlackList/temp/"/>
                    </jsp:include>
                </div>
                <br class="formBtns notRight">
                <span id="addBatchBtn" onclick="addBatch()" class="sq-button sq-button-round">导入Excel</span>
                <span  onclick="download();" class="sq-button sq-button-round">下载模板</span>
            </form>
        </div>
    </div>
</div>
<script>

    //批量导入
    function addBatch() {
        //获取上传文件地址
        var files = getUploadResultParams();
        if (files && files.length > 0) {
            var filePath = files[0].filePath;
            var fileExtension = filePath.substring(filePath.lastIndexOf('.') + 1);
            if (fileExtension !== 'xls' && fileExtension !== 'XLS' && fileExtension !== 'xlsx' && fileExtension !== 'XLSX') {
                UIUtils.alertWarning("请上传.xls或.xlsx后缀的文件!");
                return;
            }

            var _url = '<%=path%>/mcr/mcrCstBlackList/importData.do';
            AjaxUtils.ajaxPost(_url, {filePath: filePath}, function (msg) {
                if (msg.success === 1) {
                    parent.grid.reload();
                    parent.$.ligerDialog.SQalert({
                        SQ_showButtons: true,
                        SQ_onBtnclick: function (item, Dialog) {
                            console.log(item, Dialog);
                        },
                        width: 400,
                        height: 200,
                        content: msg.info
                    });
                    frameElement.dialog.close();
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }, true);
        } else {
            UIUtils.alertWarning("请先上传导入文件!");
        }
    }

    function download(){
        var wait_dialog;
        $.ajax({
            url:'<%=path%>/mcr/mcrCstBlackList/download.do',
            type:'post',
            dataType:'json',
            data:'',
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: '请稍后', SQ_type: "waitting"});
            },
            success:function(msg){
                wait_dialog.close();
                if (msg.success === 1) {
                    window.open(msg.data);
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            },
            error:function(){
                wait_dialog.close();
                $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
            }
        });
    }
</script>

</body>
</html>